class Sales::StoreOrdersController < Sales::BaseController
  before_action :set_store, :set_normal_store_id, :set_store_id, :set_cart, :set_customer
  def index
    set_search_params
    @q = @customer.orders.includes(store: [:contact_info]).ransack(params[:q])
    @orders = @q.result.order("id desc").page(params[:page])
  end

  def new
    @cart_items = @cart.items.showable
    @store_order = StoreOrder.new
  end

  private
  def set_cart
    @cart ||= current_cart
  end

  def set_customer
    @customer ||= current_customer
  end

  def set_search_params
    params[:q] ||= {}
    @company_name = params[:q][:store_name_cont]
    @numero = params[:q][:numero_cont]
    @phone_number = params[:q][:store_contact_info_tel_phone_or_store_contact_info_phone_number_or_store_admin_phone_number_cont]
    @status = params[:q][:status_eq]
    @pay_status = params[:q][:pay_status_eq]
    @start = params[:q][:created_at_gteq]
    @end = params[:q][:created_at_lteq]
    params[:q][:created_at_lteq] = params[:q][:created_at_lteq].to_date.end_of_day if params[:q][:created_at_lteq].present?
  end
end
